﻿using Newtonsoft.Json;
using PLCSharp.CoreModel.Common;
using Prism.Mvvm;
using System.Collections.ObjectModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace PLCSharp.Views.MotionController
{
    public class Interpolation : BindableBase
    {
        #region 属性
  
        private string _Name;
        /// <summary>
        /// 点名称
        /// </summary>
        public string Name
        {
            get { return _Name; }
            set { SetProperty(ref _Name, value); }
        }

        private InterpolationType _Type;
        /// <summary>
        /// 
        /// </summary>
        public InterpolationType Type
        {
            get { return _Type; }
            set { SetProperty(ref _Type, value); }
        }
 
        /// <summary>
        /// 
        /// </summary>
        public string SerializedInterpolations
        {
            get => JsonConvert.SerializeObject(_InterpolationPoints); // 自动序列化
            set
            {
                InterpolationPoints = JsonConvert.DeserializeObject<ObservableCollection<InterpolationPoint>>(value); // 自动反序列化
            }
        }


        private ObservableCollection<InterpolationPoint> _InterpolationPoints = [];
        [JsonIgnore]
        /// <summary>
        /// 
        /// </summary>
        public ObservableCollection<InterpolationPoint> InterpolationPoints
        {
            get { return _InterpolationPoints; }
            set { SetProperty(ref _InterpolationPoints, value); }
        }



        private InterpolationParams _Params;
  
        /// <summary>
        /// Comment
        /// </summary>
        public InterpolationParams Params
        {
            get
            {
                _Params ??= new InterpolationParams();

                return _Params;
            }
            set
            {
                SetProperty(ref _Params, value);
            }
        }
        public class InterpolationParams : BindableBase
        {
            private string _Prompt;
            [JsonIgnore]
            /// <summary>
            /// 提示
            /// </summary>
            public string Prompt
            {
                get { return _Prompt; }
                set { SetProperty(ref _Prompt, value); }
            }

            private ushort _Dir;
            /// <summary>
            /// 
            /// </summary>
            public ushort Dir
            {
                get { return _Dir; }
                set { SetProperty(ref _Dir, value); }
            }

            private ushort _PositionMode;
            /// <summary>
            /// 
            /// </summary>
            public ushort PositionMode
            {
                get { return _PositionMode; }
                set { SetProperty(ref _PositionMode, value); }
            }
        }
        #endregion
  
    }

    public enum InterpolationType
    {
        Line直线 = 0,
        Arc圆弧 = 1
    }
}
